<template>
  <div class="sales-view">
    <el-card shadow="hover" class="box-card">
      <div slot="header" class="clearfix">
        <div class="menu-wrap">
          <el-menu class="sales-view-menu" mode="horizontal" :default-active="activeIndex" @select="onMenuSelect">
            <el-menu-item class="el-menu-item" index="1">销售额</el-menu-item>
            <el-menu-item class="el-menu-item" index="2">访问量</el-menu-item>
          </el-menu>
          <div class="menu-right">
            <el-radio-group v-model="radioSelect" size="small">
              <el-radio-button label="今日"/>
              <el-radio-button label="本周"/>
              <el-radio-button label="本月"/>
              <el-radio-button label="今年"/>
            </el-radio-group>
            <el-date-picker class="sales-view-date-picker"
                            type="daterange"
                            v-model="date"
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            size="small"
                            unlink-panels
                            :pickerOptions="pickerOptions"
            />
          </div>
        </div>
      </div>
      <div class="sales-view-chart-wrapper">
          <!--    销售数据表  响应式布局    -->
        <v-chart :options="chartOption" :autoresize='true' />
         <!--    排行榜    -->
        <div class="sales-view-paihangbang">
          <div class="sales-view-title">排行榜</div>
          <div class="sales-view-list">
            <div class="list-item" v-for="item in rankData" :key="item.no">
              <div  :class="['list-item-no', +item.no <= 3 ? 'top-no' : '']">{{ item.no}}</div>
              <div class="list-item-name">{{item.name}}</div>
              <div class="list-item-money">{{item.money}}</div>
            </div>
          </div>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
import commonDataMixin from '../../mixins/commonDataMixin'
export default {
  name: 'SalesView',
  mixins:[commonDataMixin],
  data () {
    return {
      activeIndex: '1',
      radioSelect: '今日',
      date: null,
      pickerOptions: {
        shortcuts: [
          {
            text: '最近一周',
            onClick (picker) {
              const start = new Date()
              const end = new Date()
              start.setTime(start.getTime() - 1000 * 60 * 60 * 24 * 7)
              picker.$emit('pick', [start, end])
            }
        },
          {
            text: '最近一个月',
            onClick (picker) {
              const start = new Date()
              const end = new Date()
              start.setTime(start.getTime() - 1000 * 60 * 60 * 24 * 30)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近三个月',
            onClick (picker) {
              const start = new Date()
              const end = new Date()
              start.setTime(start.getTime() - 1000 * 60 * 60 * 24 * 90)
              picker.$emit('pick', [start, end])
            }
          }]
      },
      chartOption: {}
    }
  },
  methods: {
    onMenuSelect (index) {
      this.activeIndex = index
      if(index==='1'){
        this.render(this.orderFullYear,this.orderFullYearAxis,'年度销售额')
      }else{
        this.render(this.userFullYear,this.userFullYearAxis,'年度访问量')
      }
    },
    render(data,axis,title){
     this.chartOption={
       title:{
         text: title,
         textStyle:{
           fontSize: 12,
           color:'#666'
         },
         left: 25,
         top:20
       },
       xAxis:{
         type: 'category',
         data: axis,
         axisTick:{
           alignWithLabel: true,
           color:'#999'
         },
         axisLine:{
           lineStyle: {
             color:'#999'
           }
         },
         axisLabel:{
           color:'#333'
         }

       },
       yAxis:{
         axisLine:{
           show: false
         },
         axisTick:{
           show: false
         },
         splitLine:{
           lineStyle:{
             type: 'dotted',
             color: '#eee'
           }
         }
       },
       series:[{
         type:'bar',
         barWidth: '50%',
         data: data
       }],
       color: ['#3398db'],
       grid: {
         top:70,
         left:60,
         right:60,
         bottom:50
       }

     }
    }
  },
  computed:{
    rankData(){
      return this.activeIndex === '1' ? this.orderRank : this.userRank
    }
  },
  watch:{
    orderFullYear(){
      this.render(this.orderFullYear,this.orderFullYearAxis,'年度销售额')
    }
  }
}
</script>

<style lang="scss" scoped>
.sales-view {
  margin-top: 20px;

  .menu-wrap {
    display: flex;
    position: relative;

    .sales-view-menu {
      padding-left: 20px;
      width: 100%;

      .el-menu-item {
        height: 50px;
        line-height: 50px;
        margin: 0 20px;
      }
    }

    .menu-right {
      position: absolute;
      right: 20px;
      top: 0;
      height: 50px;
      line-height: 50px;

      .sales-view-date-picker {
        margin-left: 20px;
      }
    }
  }
  .sales-view-chart-wrapper{
    display: flex;
    height: 270px;
    .echarts{
      width: 70%;
      height: 100%;
    }
    .sales-view-paihangbang{
      flex:1;
      width:100%;
      height: 100%;
      overflow: hidden;
      .sales-view-title{
        font-size: 12px;
        color: #666;
        font-width: 500;
      }
      .sales-view-list{
        margin-top: 15px;
        .list-item{
          display: flex;
          align-items: center;
          font-size: 12px;
          height: 20px;
          padding: 6px 0 ;
          .list-item-no{
            text-align: center;
            line-height: 20px;
            width: 20px;
            height: 20px;
            color: #333;
            margin-right: 20px;
          }
          .top-no{
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background-color: #000;
            color: white;
            font-weight: 500;
          }
          .list-item-name{
            height: 20px;
            line-height: 20px;
            color: #333;
          }
          .list-item-money{
           flex: 1;
            text-align: right;
          }
        }
      }
    }
  }
}

</style>
